import Sequelize from 'sequelize'
import sequelize from './../../database'


const Trading = sequelize.define('sys_goods',{
	id:{
        type: Sequelize.UUIDV4,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        allowNull: false,
        primaryKey:true
    },
    goods_host:{
        type:Sequelize.STRING,
        allowNull: false,
    },
    goods_name:{
        type:Sequelize.STRING,
        allowNull: false,
    },
    goods_num:{
        type:Sequelize.INTEGER,
        allowNull: false,
    },
    goods_price:{
        type:Sequelize.INTEGER,
        allowNull: false,
    },
    goods_remark:{
        type:Sequelize.STRING,
        allowNull: false,
    },
    goods_status:{
    	type:Sequelize.INTEGER,
        allowNull: false,
        defaultValue:0
    },
    goods_picture:{
        type:Sequelize.STRING,
        allowNull: false,
    },
},{
    tableName: 'original_order',
    updatedAt:'updated_at',
    createdAt:'created_at'
});

class TradingModel{
	insert(record){
		return Trading.create(record);
	}
	del(id){
		return Trading.destroy({
			where:{
				id:id
			}
		});
	}
	findById(id){
		return Trading.findById(id);
	}
	findAll(){
		return Trading.findAll();
	}
	findListPage(record){
		return Trading.findAndCount({
			limit:record.page_size,
            offset: record.page_size * (record.page_no -1)
		})
	}
	update(record){
		return Ability.update(record,{
			'where':{
				"id":record.id
			}
		})
	}

}
module.exports = new TradingModel();